﻿<UserControl x:Class="Core.Views.NotificationsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:class="clr-namespace:Core.Class"
             xmlns:helpers="clr-namespace:Helpers;assembly=Helpers"
             xmlns:selectors="clr-namespace:Controls.Selectors;assembly=Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.Resources>

            <Style x:Key="TitleNotification" TargetType="TextBlock">
                <Setter Property="Foreground" Value="{DynamicResource BrushBackgroundLateralMenu}"/>
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsRead}" Value="False">
                        <Setter Property="Foreground" Value="{DynamicResource ColorThemeBrush}" />
                        <Setter Property="FontWeight" Value="SemiBold" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
            
            <!-- Templates des notifications -->
            <DataTemplate x:Key="NotificationSystemItemTemplateBase" DataType="{x:Type ListBoxItem}">
                <Grid Height="50">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <!-- Logo notification -->
                    <Border Background="Transparent" Grid.Column="0" Grid.Row="0"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Viewbox Width="17.439" Height="23.119">
                            <Canvas Width="17.439" Height="23.119">
                                <Canvas>
                                    <Canvas>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 1.949,1.883"/>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 16.614,0.000 L 5.176,0.000 C 4.722,0.000 3.979,0.000 3.523,0.000 L 2.248,0.000 C 1.795,0.000 1.145,0.245 0.804,0.546 L 0.620,0.706 C 0.278,1.008 0.000,1.626 0.000,2.080 L 0.000,2.709 L 0.000,2.848 L 0.000,22.292 C 0.000,22.747 0.372,23.119 0.826,23.119 L 15.190,23.119 C 15.646,23.119 16.017,22.747 16.017,22.292 L 16.017,2.709 C 16.017,2.256 15.646,1.885 15.190,1.885 L 5.588,1.885 C 5.588,1.583 5.345,1.341 5.045,1.341 C 4.744,1.341 4.501,1.583 4.501,1.885 L 4.501,2.099 L 4.501,7.553 L 3.133,6.216 L 1.949,7.553 L 1.949,1.883 L 0.826,1.883 C 0.819,1.883 0.814,1.886 0.810,1.887 L 1.697,0.868 L 4.350,0.868 L 16.601,0.868 L 16.601,21.510 L 16.612,21.510 C 17.067,21.510 17.439,21.138 17.439,20.683 L 17.439,0.825 C 17.439,0.372 17.069,0.000 16.614,0.000 Z"/>
                                    </Canvas>
                                </Canvas>
                            </Canvas>
                        </Viewbox>
                    </Border>

                    <!-- Textes -->
                    <Grid Grid.Column="1" Grid.Row="0" Margin="15,0,15,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Sujet}" Style="{StaticResource TitleNotification}" FontSize="18" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" />
                        <TextBlock Text="{Binding SysDateCreation, StringFormat={}{0:f}}" Foreground="{DynamicResource BrushBackgroundLateralLightMenu}" FontSize="12" Grid.Column="1" Grid.Row="1" />
                    </Grid>
                </Grid>
            </DataTemplate>
            
            <!-- Default -->
            <DataTemplate x:Key="NotificationUserItemTemplateBase" DataType="{x:Type ListBoxItem}">
                <Grid Height="50" x:Name="GridItem">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Column="0" Visibility="Collapsed" HorizontalAlignment="Left" IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
                    
                    <!-- Logo notification -->
                    <Border Background="Transparent" Grid.Column="1" Grid.Row="0"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Viewbox Width="17.439" Height="23.119">
                            <Canvas Width="17.439" Height="23.119">
                                <Canvas>
                                    <Canvas>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 1.949,1.883"/>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 16.614,0.000 L 5.176,0.000 C 4.722,0.000 3.979,0.000 3.523,0.000 L 2.248,0.000 C 1.795,0.000 1.145,0.245 0.804,0.546 L 0.620,0.706 C 0.278,1.008 0.000,1.626 0.000,2.080 L 0.000,2.709 L 0.000,2.848 L 0.000,22.292 C 0.000,22.747 0.372,23.119 0.826,23.119 L 15.190,23.119 C 15.646,23.119 16.017,22.747 16.017,22.292 L 16.017,2.709 C 16.017,2.256 15.646,1.885 15.190,1.885 L 5.588,1.885 C 5.588,1.583 5.345,1.341 5.045,1.341 C 4.744,1.341 4.501,1.583 4.501,1.885 L 4.501,2.099 L 4.501,7.553 L 3.133,6.216 L 1.949,7.553 L 1.949,1.883 L 0.826,1.883 C 0.819,1.883 0.814,1.886 0.810,1.887 L 1.697,0.868 L 4.350,0.868 L 16.601,0.868 L 16.601,21.510 L 16.612,21.510 C 17.067,21.510 17.439,21.138 17.439,20.683 L 17.439,0.825 C 17.439,0.372 17.069,0.000 16.614,0.000 Z"/>
                                    </Canvas>
                                </Canvas>
                            </Canvas>
                        </Viewbox>
                    </Border>

                    <!-- Textes -->
                    <Grid Grid.Column="2" Grid.Row="0" Margin="15,0,15,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Sujet}" Style="{StaticResource TitleNotification}" FontSize="18" Grid.Column="0" Grid.Row="0" />
                        <TextBlock Text="{Binding Resume}" Foreground="{DynamicResource BrushBackgroundLateralMenu}" FontSize="12" Grid.Column="0" Grid.Row="1"/>
                        <TextBlock Text="{Binding SysDateCreation, StringFormat={}{0:f}}" Foreground="{DynamicResource BrushBackgroundLateralLightMenu}" FontSize="12" Grid.Column="1" Grid.Row="1" />
                    </Grid>
                </Grid>
            </DataTemplate>
            
            <!-- Appel -->
            <DataTemplate x:Key="NotificationUserItemTemplateAppel" DataType="{x:Type ListBoxItem}">
                <Grid Height="50">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Column="0" Visibility="Collapsed" HorizontalAlignment="Left" IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
                    
                    <!-- Logo notification -->
                    <Border Background="Transparent" Grid.Column="1" Grid.Row="0"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Viewbox Width="22.948" Height="23.147" VerticalAlignment="Center" HorizontalAlignment="Left">
                            <Canvas Width="22.948" Height="23.147">
                                <Canvas>
                                    <Canvas>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 2.880,13.095 C 6.026,18.199 8.081,19.993 9.396,21.056 C 10.715,22.168 11.882,22.821 12.802,23.071 C 13.687,23.265 14.578,23.085 15.382,22.590 C 16.108,22.142 16.363,21.614 16.363,21.614 L 17.411,20.020 C 17.688,19.612 17.440,19.211 17.266,19.055 C 17.183,18.921 17.159,18.883 17.196,18.728 C 17.231,18.573 17.188,18.416 16.925,18.289 L 13.780,16.611 C 13.505,16.465 13.467,16.488 13.276,16.605 C 13.108,16.762 13.085,16.724 12.930,16.688 C 12.869,16.672 12.247,16.607 12.013,17.253 L 11.581,18.522 C 11.435,18.797 11.375,18.701 11.100,18.555 C 10.383,18.204 8.966,17.574 7.823,15.720 L 3.758,9.125 C 3.758,9.125 3.278,8.049 3.151,7.757 C 3.020,7.416 3.021,7.204 3.360,6.812 L 4.001,6.310 L 5.224,6.241 C 5.655,6.213 6.115,5.930 5.942,5.351 L 4.598,0.560 C 4.472,0.269 4.258,-0.206 3.549,0.099 L 2.012,0.730 C 1.625,0.916 1.491,0.998 1.396,1.057 C 1.300,1.115 0.996,1.223 0.660,1.748 C 0.377,2.186 0.134,2.520 0.071,3.060 C -0.009,3.531 -0.119,5.235 0.351,7.108 C 0.836,9.052 1.572,10.974 2.880,13.095"/>
                                    </Canvas>
                                    <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 14.638,0.499 L 18.918,0.499 L 18.918,4.531 L 22.948,4.531 L 22.948,8.797 L 18.950,8.797 L 18.950,12.821 L 14.655,12.821 L 14.655,8.797 L 10.624,8.797 L 10.624,4.531 L 14.638,4.531 L 14.638,0.499 Z"/>
                                </Canvas>
                            </Canvas>
                        </Viewbox>
                    </Border>
                    
                    <!-- Textes -->
                    <Grid Grid.Column="2" Grid.Row="0" Margin="15,0,15,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Sujet}" Style="{StaticResource TitleNotification}" FontSize="18" Grid.Column="0" Grid.Row="0" />
                        <TextBlock Text="{Binding Resume}" Foreground="{DynamicResource BrushBackgroundLateralMenu}" FontSize="12" Grid.Column="0" Grid.Row="1"/>
                        <StackPanel Orientation="Vertical" Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Bottom">
                            <TextBlock Text="{Binding SysDateCreation, StringFormat={}{0:f}}" Foreground="{DynamicResource BrushBackgroundLateralLightMenu}" FontSize="12" />
                        <TextBlock Text="{Binding UtilisateurCible, StringFormat='adressé à {0}'}" Visibility="{Binding UtilisateurCible, Converter={StaticResource StringValueVisibilityConverter}}" Foreground="{DynamicResource BrushBackgroundLateralLightMenu}" FontSize="12" />
                    </StackPanel>
                    </Grid>
                </Grid>
            </DataTemplate>

            <DataTemplate x:Key="NotificationUserItemTemplateEtude" DataType="{x:Type ListBoxItem}">
                <Grid Height="50" x:Name="GridItem">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="50" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Column="0" Visibility="Collapsed" HorizontalAlignment="Left" IsChecked="{Binding IsSelected, Mode=TwoWay}"/>

                    <!-- Logo notification -->
                    <Border Background="Transparent" Grid.Column="1" Grid.Row="0"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                        <Viewbox Width="17.439" Height="23.119">
                            <Canvas Width="17.439" Height="23.119">
                                <Canvas>
                                    <Canvas>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 1.949,1.883"/>
                                        <Path Fill="{DynamicResource ColorThemeBrush}" Data="F1 M 16.614,0.000 L 5.176,0.000 C 4.722,0.000 3.979,0.000 3.523,0.000 L 2.248,0.000 C 1.795,0.000 1.145,0.245 0.804,0.546 L 0.620,0.706 C 0.278,1.008 0.000,1.626 0.000,2.080 L 0.000,2.709 L 0.000,2.848 L 0.000,22.292 C 0.000,22.747 0.372,23.119 0.826,23.119 L 15.190,23.119 C 15.646,23.119 16.017,22.747 16.017,22.292 L 16.017,2.709 C 16.017,2.256 15.646,1.885 15.190,1.885 L 5.588,1.885 C 5.588,1.583 5.345,1.341 5.045,1.341 C 4.744,1.341 4.501,1.583 4.501,1.885 L 4.501,2.099 L 4.501,7.553 L 3.133,6.216 L 1.949,7.553 L 1.949,1.883 L 0.826,1.883 C 0.819,1.883 0.814,1.886 0.810,1.887 L 1.697,0.868 L 4.350,0.868 L 16.601,0.868 L 16.601,21.510 L 16.612,21.510 C 17.067,21.510 17.439,21.138 17.439,20.683 L 17.439,0.825 C 17.439,0.372 17.069,0.000 16.614,0.000 Z"/>
                                    </Canvas>
                                </Canvas>
                            </Canvas>
                        </Viewbox>
                    </Border>

                    <!-- Textes -->
                    <Grid Grid.Column="2" Grid.Row="0" Margin="15,0,15,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Sujet}" Style="{StaticResource TitleNotification}" FontSize="18" Grid.Column="0" Grid.Row="0" />
                        <TextBlock Text="{Binding Resume}" Foreground="{DynamicResource BrushBackgroundLateralMenu}" FontSize="12" Grid.Column="0" Grid.Row="1"/>
                        <TextBlock Text="{Binding SysDateCreation, StringFormat={}{0:f}}" Foreground="{DynamicResource BrushBackgroundLateralLightMenu}" FontSize="12" Grid.Column="1" Grid.Row="1" />
                    </Grid>
                </Grid>
            </DataTemplate>

            <!-- Selection -->
            <selectors:NotificationsDataTemplateSelector x:Key="NotificationsDataTemplateSelector" DefaultNotification="{StaticResource NotificationUserItemTemplateBase}" AppelNotification="{StaticResource NotificationUserItemTemplateAppel}" EtudeNotification="{StaticResource NotificationUserItemTemplateEtude}" />
    </UserControl.Resources>

    <controls:MetroContentControl Margin="20">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="70" />
            </Grid.RowDefinitions>
        
            <Grid Margin="20" Background="White" Grid.Column="0" Grid.Row="0">
            
                    <TabControl Margin="10">
                
                        <!-- Utilisateur -->
                        <TabItem Header="{helpers:Localize NotificationTabItem_MesNotifications}"  Foreground="{DynamicResource LabelForegroundBrush}">
                            <Grid Width="750" HorizontalAlignment="Left">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                            
                                <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,15,0,0">
                                    <Label Content="Modules :" />
                                    <ComboBox Width="150" Height="25" Margin="3,0,0,0" ItemsSource="{Binding ModulesNotifications}" SelectedItem="{Binding SelectedModuleNotification, Mode=TwoWay}" DisplayMemberPath="Libelle" />
                                
                                    <Label Content="Etat :" Margin="50,0,0,0"/>
                                    <ComboBox Width="150" Height="25" Margin="3,0,0,0" ItemsSource="{Binding StatutsNotifications}" SelectedItem="{Binding SelectedStatutNotification, Mode=TwoWay}" DisplayMemberPath="Libelle" />
                                </StackPanel>
                                <ListBox Tag="{helpers:Localize NotificationTabItem_MesNotifications}" Margin="0,30,10,10" Grid.Row="1" ItemsSource="{Binding NotificationUsers}" ItemTemplateSelector="{StaticResource NotificationsDataTemplateSelector}" SelectedItem="{Binding SelectedNotificationUser, Mode=TwoWay}" HorizontalAlignment="Stretch"/>
                            </Grid>
                        </TabItem>
            
                        <!-- Systémes -->
                        <TabItem Header="{helpers:Localize NotificationTabItem_NotificationsSystem}" Foreground="{DynamicResource LabelForegroundBrush}" Visibility="{helpers:AccessFunctionVisibility 0, Core}">
                            <Grid Width="750" HorizontalAlignment="Left">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,15,0,0">
                                    <Label Content="Etat :" />
                                    <ComboBox Width="150" Height="25" Margin="3,0,0,0" ItemsSource="{Binding StatutsNotifications}" SelectedItem="{Binding SelectedStatutNotificationSystem, Mode=TwoWay}" DisplayMemberPath="Libelle" />
                                </StackPanel>
                                <ListBox Tag="{helpers:Localize NotificationTabItem_NotificationsSystem}" Margin="0,30,10,10" Grid.Row="1" ItemsSource="{Binding Notifications}" ItemTemplate="{StaticResource NotificationSystemItemTemplateBase}" SelectedItem="{Binding SelectedNotification, Mode=TwoWay}" />
                            </Grid>
                        </TabItem>
                    </TabControl>
            </Grid>

            <!-- Fermeture -->
            <StackPanel Margin="20,10,20,20" Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
                <Button Content="{helpers:Localize Generic_Fermer}" Style="{DynamicResource MetroFlatButtonStevia}" Command="{Binding CancelCommand}"/>
            </StackPanel>
        </Grid>
    </controls:MetroContentControl>
</UserControl>
